#include <string.h>
#include <stdio.h>
#include "sm3.h"
#include "time.h"
#define MAX_STR_LENGTH 501  // 16K

int main( int argc, char *argv[] )
{
	printf("\n================================================================================================================================================================= \n \n");	
	char input[MAX_STR_LENGTH];  // 加1用于存储字符串结尾的空字符

    const char* message = "In this beautiful campus, there are lush trees and flowers blooming everywhere. Every corner of the campus is filled with the youthful atmosphere. On the spacious playground, sunlight shines down as students run and play with joyful laughter. Inside the teaching buildings, sparks of wisdom fill the air as teachers nurture the knowledge of their students. The library is quiet and cozy, serving as a treasure trove of knowledge. The cafeteria offers a variety of delicious.Delicious! Delicious!!!!!";
    size_t messageLength = strlen(message);

    size_t currentIndex = 0;


    strncpy(input + currentIndex, message, messageLength);
	input[MAX_STR_LENGTH] = '\0';
	int ilen = MAX_STR_LENGTH;
	uint8_t output[32];
	int i;
	sm3_context ctx;

	printf("Message:\n");
	printf("  %s\n", input);
	clock_t begin, end;
	begin = clock();
	sm3(input, ilen, output);
	end = clock();
	double d = (double)(end- begin)*1000/CLOCKS_PER_SEC;
	printf("Hash:\n   ");
	for (i = 0; i < 32; i++)
	{
		printf("%02x", output[i]);
		if (((i + 1) % 4 ) == 0) printf(" ");
	}
	printf("\ntime: %f ms \n", d);
	printf("\n================================================================================================================================================================= \n");

	// printf("Message:\n");
	// for (i = 0; i < 16; i++)
	// 	printf("abcd");
	// printf("\n");

	// sm3_starts( &ctx );
	// for (i = 0; i < 16; i++)
	// 	sm3_update( &ctx, "abcd", 4 );
	// sm3_finish( &ctx, output );
	// memset( &ctx, 0, sizeof( sm3_context ) );

	// printf("Hash:\n   ");
	// for (i = 0; i < 32; i++)
	// {
	// 	printf("%02x", output[i]);
	// 	if (((i + 1) % 4 ) == 0) printf(" ");
	// }
	// printf("\n");
	//getch();	//VS2008
}